package com.day14;

import org.junit.Test;

import java.util.Date;
import java.util.Scanner;

/**
 * 一.异常的体系结构
 * java.lang.Throwable
 *      |------java.lang.Errot:java虚拟机错误，无法处理，只能避免
 *      |------java.lang.Exception:java异常，可以进行异常的处理
 *          |----编译时异常(checked):编译时就出现问题的
 *              |----IOException
 *                  |----FileNotFoundException
 *              |----ClassNotFoundException
 *
 *          |----运行时异常(unchecked):编译通过，只有运行时才抛出异常的情况。
 *              |------NullPointerException
 *              |------ArrayIndexOutOfBoundsException
 *              |------ClassCastException
 *              |------NumberFormatException
 *              |------InputMismatchException
 *              |------ArithmeticException
 *
 * 面试题:常见的异常都有哪些?举例说明
 *
 *
 *
 *
 */
public class ExceptionTest {





//    ArithmeticException
    @Test
    public void test6(){
        int a = 10;
        int b = 0;
        System.out.println(a / b);
    }

//    InputMismatchException
    @Test
    public void test5(){
        Scanner scanner = new Scanner(System.in);
        int nextInt = scanner.nextInt();
        System.out.println(nextInt);
    }



    //NumberFormatException
    @Test
    public void test4(){
        String string = "abc";
        Integer integer = Integer.valueOf(string);
        System.out.println(integer);
    }



    //ClassCastException
    @Test
    public void test3(){
//        String string = (String)new Date();
        Object object = new Date();
        String object1 = (String) object;
        System.out.println(object1);
    }



//    ArrayIndexOutOfBoundsException
    @Test
    public void test2(){
        int[] arr = new int[10];
        System.out.println(arr[10]);
    }



    //NullPointerException
    @Test
    public void test1(){
//        int[] arr = null;
//        System.out.println(arr[3]);


        String str = "abc";
        str = null;
        System.out.println(str.charAt(0));
    }


}
